<?php defined('IN_ADMIN') or exit('Access Denied!'); ?>
<style>
.zonebox{float:left;width:90px;height:20px;overflow:hidden;}
</style>
<form action="/admin/waimai/save/<?=intval($shop_id);?>" method="post" id="myform">
  <input type="hidden" name="method" value="<?=$method;?>" />
  <div class="pad-10">
    <div class="col-tab">
      <ul class="tabBut cu-li" id="tab_setting">
        <li id="tab_setting_1" class="on">配送区域</li>
      </ul>
      <div id="show_div_1" class="content pad-10">
        <table width="100%" id="city_table" class="table_form">
        <tr>
          <td class="y-bg" colspan="3"><input type="checkbox" name="city_deliver" id="city_deliver" value="1" <?php if(isset($deliver[0]) && $deliver[0]) echo 'checked';?> />
            <label for="city_deliver">全市配送</label></td>
        </tr>
        </table>
        <table width="100%" id="zone_table" class="table_form">
            <?php
                $list = $zone->getZoneList(0);
                foreach($list as $zid => $mainZone){
                    $zone_all = isset($deliver[$zid]) ? $deliver[$zid] : 0;
            ?>
            <tr>
              <td class="y-bg" valign="top" width="50"><?=$mainZone->name;?></td>
              <td class="y-bg" valign="top" width="30"><?php echo zone_checkbox('zone_all', '全区', $zid, $zone_all);?> &nbsp; </td>
              <td class="y-bg">
              <div id="zone_div_<?=$zid;?>">
                  <?php
                        $sublist = $zone->getZoneList($zid);
                        if(is_array($sublist)){
                            foreach($sublist as $subid => $subZone){
                                echo zone_checkbox('deliver_zone', $subZone->name, $subid, isset($deliver[$subid]));
                            }
                        }
                    ?>
                </div></td>
            </tr>
            <?php
                }
            ?>
        </table>
        </td>
        </tr>
        </tbody>
        </table>
      </div>
      <div class="bk15"></div>
      <input name="dosubmit" id="dosubmit" type="submit" value="提交" class="button">
    </div>
  </div>
</form>
<script type="text/javascript">
$(document).ready(function(){
    //Checkbox选中状态
    $("input[type=checkbox]").each(function(){
        var label = $(this).next();
        if($(this).attr("checked")){
            label.css({"color":"blue","font-weight":"bold"});
        }else{
            label.css({"color":"","font-weight":"normal"});
        }
    }).change(function(){
        var label = $(this).next();
        if($(this).attr("checked")){
            label.css({"color":"blue","font-weight":"bold"});
        }else{
            label.css({"color":"","font-weight":"normal"});
        }
    });
    //配送区域相关
    $("#city_deliver").each(function(){
        if(this.checked){
            $("#zone_table").hide();
        }else{
            $("#zone_table").show()
        }
    }).change(function(){
        if(this.checked){
            $("#zone_table").hide();
        }else{
            $("#zone_table").show()
        }
    });
    $("input[id^='zone_all']").each(function(){
        var zid = $(this).val();
        if(this.checked){
            $("#zone_div_" + zid).hide();
        }else{
            $("#zone_div_" + zid).show()
        }
    }).change(function(){
        var zid = $(this).val();
        if(this.checked){
            $("#zone_div_" + zid).hide();
        }else{
            $("#zone_div_" + zid).show();
        }
    });
});
</script>
<?php
    //
    function zone_checkbox($name, $label, $value, $checked){
        $checked = $checked ? ' checked' : '';
        $id  = $name. '_' .$value;
        $str = '<div class="zonebox">';
        $str.= '<input type="checkbox" name="' .$name. '[]" id="' .$id. '" value="' .$value. '"' .$checked.' />';
        $str.= '<label for="' .$id. '">'.h($label).'</label></div>';
        return $str;
    }
?>
